package controls;

import java.util.LinkedList;

import javax.swing.JComboBox;

import main.Application;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


public class EnumDropDownList extends JComboBox{
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public EnumDropDownList(Node enumNode)
	{
		super();
		LinkedList<String> enumsToAdd = new LinkedList<String>();
		NodeList enumNames = enumNode.getChildNodes();
		for (int i = 0; i < enumNames.getLength(); ++i)
		{
			try
			{
				if(enumNames.item(i).getNodeName().equals("#text"))
					continue;
				Element item = (Element) enumNames.item(i);  
				enumsToAdd.add(enumElementToString(item));
			}
			catch (Exception e)
			{
				Application.getInstance().notifyAboutException(e);
			}
		}

		
		for (int i=0; i<enumsToAdd.size(); ++i)
			this.addItem(enumsToAdd.get(i));

	}

	private String enumElementToString(Element item){
		String result = item.getAttribute("enumName");
//		System.out.println("konwersja do string " +result);
		return result;
	}
	
	public EnumDropDownList(String[] stringTab)
	{
	super(stringTab);	
	}
	
}
